package com.gbas.comu.dao;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;

import javax.persistence.EntityManager;
import java.io.Serializable;
import java.util.List;
import java.util.Map;


public interface DAO<T, ID extends Serializable> {
    Class<T> getEntityClass();

    T findById(final ID id);

    List<T> findAll();

    List<T> findByExample(final T exampleInstance);

    List<T> findByNamedQuery(
            final String queryName,
            Object... params
    );


    List<T> findByNamedQueryAndNamedParams(
            final String queryName,
            final Map<String, ? extends Object> params
    );

    int countAll();

    int countByExample(final T exampleInstance);

    T save(final EntityManager em, final T entity);

    void delete(final EntityManager em, final T entity);

    EntityManager getEntityManager();

    List<T> findByCriteria(Criterion... criterion);

    List<T> findByCriteria(Order order, Criterion... criterion);

    @SuppressWarnings("unchecked")
    List<T> findByCriteria(int firstResult,
                           int maxResults, Criterion... criterion);

    @SuppressWarnings("unchecked")
    List<T> findByCriteria(int firstResult,
                           int maxResults, Order order, Criterion... criterion);

    int countByCriteria(Criterion... criterion);
}
